$(function(){
    $("#button").click(function(){
        var address = $("#address").val();
        if(address==""){
            layer.msg("请填写正确的地址");
        }
        var trytime = $("#trytime").val();
        if(trytime==""){
            layer.msg("请填写试驾时间");
        }
        var token =localStorage.phone;
        $.ajax({
            url:"https://newapp.icandrive.cn/api/testDrive.php",
            type:'post',
            dataType:'json',
            data:{address:address,time:trytime,token:token},
            success:function(data){
                if(data.status==200){
                    layer.msg("试驾预约成功");
                    setInterval(function(){
                        window.location.href="../index/index.html";
                    },2000);
                }
                if(data.status==250){
                    layer.msg("请重新登录");
                    setInterval(function(){
                        window.location.href="../login/log_in.html";
                    },2000);
                }
                if(data.status==400){
                    layer.msg("申请失败请重新申请");

                }
                if(data.status==450){
                    layer.msg("你已经申请过试驾了");
                    setInterval(function(){
                        window.location.href="../index/index.html";
                    },2000);
                }
            },
            error:function(){
                layer.msg('系统繁忙',function(){
                    history.go(0)
                },1000);
            }
        });

    });

});
